<template>
  <zh-form-card title="基本信息" :span="24">
    <zh-form ref="formRef" :model="data.formData" label-width="200px" :span="12" :rules="data.rules">
            <zh-form-input
          prop="jhApplyId"
          label="金华报名专库id"
          type="number"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.jhApplyId"
      ></zh-form-input>
      <zh-form-input
          prop="importBatchId"
          label="导入批次id"
          type="number"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.importBatchId"
      ></zh-form-input>
      <zh-form-input
          prop="year"
          label="年份"
          type="number"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.year"
      ></zh-form-input>
      <zh-form-input
          prop="schoolCategory"
          label="学段：1:幼儿园 2：小学 3：初中"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.schoolCategory"
      ></zh-form-input>
      <zh-form-input
          prop="cardType"
          label="证件类型：01：身份证 02：护照03：台胞证04：台湾居民来往大陆通行证 05：港澳居民往来内地通行证 06:外国人永久居留身份证  99：其他证件"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.cardType"
      ></zh-form-input>
      <zh-form-input
          prop="name"
          label="姓名"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.name"
      ></zh-form-input>
      <zh-form-input
          prop="idcard"
          label="证件号码"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.idcard"
      ></zh-form-input>
      <zh-form-input
          prop="approveState"
          label="审核状态:1 通过 2 不通过"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.approveState"
      ></zh-form-input>
      <zh-form-input
          prop="approveHuman"
          label="审核人"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.approveHuman"
      ></zh-form-input>
      <zh-form-date
          prop="approveTime"
          label="审核时间"
          type="datetime"
          :disabled="props.disabled"
          v-model="data.formData.approveTime"
          :span="8"
      ></zh-form-date>
      <zh-form-input
          prop="approveOpinion"
          label="审核意见"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.approveOpinion"
      ></zh-form-input>
      <zh-form-input
          prop="applyCountyCode"
          label="报名所在区县码"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.applyCountyCode"
      ></zh-form-input>
      <zh-form-input
          prop="applyCountyName"
          label="报名所在区县名"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.applyCountyName"
      ></zh-form-input>
      <zh-form-input
          prop="auditSyncFlag"
          label="审核同步状态 0 未同步 1 同步成功 2同步失败"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.auditSyncFlag"
      ></zh-form-input>
      <zh-form-input
          prop="auditSyncRemark"
          label="审核同步备注"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.auditSyncRemark"
      ></zh-form-input>
    </zh-form>
  </zh-form-card>
</template>

<script lang="ts" setup name="eduSyncDyApproveForm">
import { ElMessage } from 'element-plus';

//------------------定义子组件---------------------------
const formRef = ref();
//------------------接收传入参数(组件)-------------------
const props = defineProps({
  jhApproveId: {
    type: String,
    default: '',
  },
  disabled: {
    type: Boolean,
    default: true,
  },
  btnLoding: Boolean,
});
const emits = defineEmits(['update:btnLoding', 'canner', 'refreshTable']);
//------------------初始化------------------------------
onMounted(() => {
  getDict();
  getsurveyInfo();
});
//------------------内部变量定义-------------------------
const data = reactive({
  formData: {} as any,
  detailVisible: true,
  loading: false,
  rules: {
  },
  dictData: {} as any,
  areaCodeDict: [] as any,
  campusParam: {} as any,
});

// 查询数据字典信息
const getDict = () => {
  const params = {} as any;
  params.dictFields = '';
  $api.common.getBatchDict.post(params).then((res) => {
    data.dictData = res.result;
  });
};

//获取详情
const getsurveyInfo = () => {
  if (!props.jhApproveId) {
    return;
  }
  data.loading = true;
  $api.common.send
  .post('eduSyncDyApprove0002', { jhApproveId: props.jhApproveId })
  .then((res: any) => {
    data.formData = res.result || {};
    data.loading = false;
    data.campusParam.schoolId = data.formData.schoolId;
  })
  .catch(() => {
    data.loading = false;
  });
};

//保存
async function saveBase() {
  let checkFlag = await formRef.value.checkForm();
  if (checkFlag) {
    if (data.formData.jhApproveId) {
      $api.common.send
      .post('eduSyncDyApprove0005', data.formData)
      .then(() => {
        ElMessage.success('修改成功');
        emits('update:btnLoding', false);
        emits('canner', (data.detailVisible = false));
        emits('refreshTable');
      })
      .catch(() => {
        emits('update:btnLoding', false);
        emits('canner', (data.detailVisible = true));
      });
    } else {
      $api.common.send
      .post('eduSyncDyApprove0004', data.formData)
      .then(() => {
        ElMessage.success('新增成功');
        emits('update:btnLoding', false);
        emits('canner', (data.detailVisible = false));
        emits('refreshTable');
      })
      .catch(() => {
        emits('update:btnLoding', false);
        emits('canner', (data.detailVisible = true));
      });
    }
  }
}

//------------设置给父组件调用的数据/方法(组件)-----------
defineExpose({ saveBase });
</script>
<style lang="scss" scoped></style>
